<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>

</head>
<body>
<h1 id="time"></h1>
<script type="text/javascript">
    var time = document.getElementById('time');
    var num = 3;
    var clock = setInterval(function () {
        if (num === 0) {

            clearInterval(clock);

        }
        //(num ===0)?(num--):clearInterval(clock);
        time.innerHTML = num--;

    }, 1000);


</script>
</body>
</html>